<?php

namespace common\models\form;

use Yii;

/**
 * This is the model class for table "{{%form}}".
 *
 * @property int $id
 * @property string $name 表单标识名称
 * @property string $label 名称
 * @property string|null $description 说明
 * @property int $user_id 用户ID
 * @property int $type 表单类型
 * @property int $status 状态
 * @property int $created_at 创建时间
 * @property int $updated_at 更新时间
 * @property int $deleted_at 删除时间
 */
class Form extends \common\db\ActiveRecord {

    /**
     * {@inheritdoc}
     */
    public static function tableName() {
        return '{{%form}}';
    }

    /**
     * {@inheritdoc}
     */
    public function rules() {
        return [
            [['name', 'label'], 'required'],
            [['user_id', 'type', 'status', 'created_at', 'updated_at', 'deleted_at'], 'integer'],
            [['name'], 'string', 'max' => 20],
            [['label'], 'string', 'max' => 50],
            [['description'], 'string', 'max' => 255],
            [['name'], 'unique'],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels() {
        return [
            'id' => 'ID',
            'name' => '表单标识名称',
            'label' => '名称',
            'description' => '说明',
            'user_id' => '用户ID',
            'type' => '表单类型',
            'status' => '状态',
            'created_at' => '创建时间',
            'updated_at' => '更新时间',
            'deleted_at' => '删除时间',
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function getInputFields() {
        return $this->hasMany(FormField::class, ['form_id' => 'id']);
    }

    /**
     * {@inheritdoc}
     */
    public function fields() {
        return [
            'id',
            'name',
            'label',
            'description',
            'inputFields',
        ];
    }

}
